package com.selangshiwo.sina.impl;

import com.selangshiwo.Util;
import com.selangshiwo.sina.Weibo;
import com.selangshiwo.sina.biz.PreLoginBiz;
import com.selangshiwo.sina.biz.SSOLoginBiz;
import com.selangshiwo.sina.biz.WeiboLoginBiz;
import com.selangshiwo.sina.biz.WeiboSendMsgBiz;

public class SinaClient implements Weibo {
	
	public SinaClient(){
	}
	
	@Override
	public int weiboLogin(String uName, String uPwd) {
		
		PreLoginBiz preLogin = new PreLoginBiz(uName);
		preLogin.run();
		
		SSOLoginBiz ssoLogin = new SSOLoginBiz(uName, uPwd, preLogin.getNonce(), preLogin.getServertime(), preLogin.getPcid());
		ssoLogin.run() ;
		
		WeiboLoginBiz weiboLogin = new WeiboLoginBiz(ssoLogin.getStrWeiboUrl());
		weiboLogin.run();
		
		//填充userinfo,完成后可以发送微博
		if(weiboLogin.isLoginSuccess()){
			Util.log(weiboLogin.getUserInfo().get("userid") + " -> 登录成功!");
		
			return 0;
		}else
			return -1 ;
	}

	@Override
	public void send(String msgText) {
		// TODO Auto-generated method stub
		WeiboSendMsgBiz biz = new WeiboSendMsgBiz();
		biz.setMsgText(msgText);
		biz.run() ;
		
		if("100000".equals(biz.getResultCode())){
			Util.log("发送信息成功!");
		}else{
			Util.log("发送微博失败,returnCode=" + biz.getResultCode());
		}
		
	}


	@Override
	public void sendMessgae(String toUserId, String msg) {
		// TODO Auto-generated method stub

	}

}
